import config from '@/config/config.js';
import axios from "axios";

const warehouseRequest = {
    loadWarehouseList(searchWarehouse,pageNum,limit,callback){
        let url = config.warehouseBaseUrl + "/warehouse/list?pageNum=" + pageNum + "&limit=" + limit
        if (searchWarehouse.warehouseId){
            url += "&warehouseId=" + searchWarehouse.warehouseId
        }
        if (searchWarehouse.warehouseName){
            url += "&warehouseName=" + searchWarehouse.warehouseName
        }
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data.data)
        })
    },
    loadUpdateInfo(warehouseId,callback){
        let url = config.warehouseBaseUrl + "/warehouse/updateInfo?warehouseId=" + warehouseId
        axios.get(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    deleteWarehouse(warehouseId,callback){
        let url = config.warehouseBaseUrl + "/warehouse/delete?warehouseId=" + warehouseId
        axios.delete(url,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    updateWarehouse(updateWarehouse,callback){
        let url = config.warehouseBaseUrl + "/warehouse/update"
        axios.put(url,updateWarehouse,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    },
    insertWarehouse(insertWarehouse,callback){
        let url = config.warehouseBaseUrl + "/warehouse/insert"
        axios.post(url,insertWarehouse,{
            headers:{
                token:localStorage.getItem("token")
            }
        }).then(res=>{
            callback(res.data)
        })
    }
}
export default warehouseRequest;